import Taro, { Component, useState, useEffect } from '@tarojs/taro';
import { View, Input, Image, Picker } from '@tarojs/components';
import Address from '../../../components/address';
import Next from '../../../static/user/icon_next.png';
import NavigationBar from '../../../components/navigationBar/index';

import { agentInfoDetail } from '../../../services/user'

import './index.scss';

function Apply() {
  const [form, setForm] = useState({
  });
  const userInfo = Taro.getStorageSync('userInfo');
  const [cardType, setCardType] = useState([]);
  const [list, setList] = useState([]);
  const [isSelected, setIsSelected] = useState(false);
  const [type, setType] = useState(false);

  let navigationBarHeight = Taro.getStorageSync('navigationBarHeight');


  function handleText(key, e) {
    const value = {
      ...form,
    }
    value[key] = e.target.value;
    setForm(value);
  }

  useEffect(() => {
    setCardType([{ text: '用户编辑', value: 1 }, { text: '后台编辑', value: 2 }])
    agentInfoDetail().then(ele => {
      if (ele) {
        setType(true)
        if (ele.type == 1) {
          ele.type = '用户编辑'
        } else if (ele.type == 2) {
          ele.type = '后台编辑'
        }
        setForm(ele)
      }
    })
  }, []);

  function handleType(e) {
    setForm({
      ...form,
      typeIndex: e.target.value,
      type: cardType[e.target.value].value
    })
  }

  function handleSubmit() {
    Taro.navigateTo({
      url: '/subPacKagebWork/pages/agent-remarks/index?type=create',
    });
  }
  function handleedit() {
    Taro.navigateTo({
      url: '/subPacKagebWork/pages/agent-remarks/index?type=edit',
    });
  }

  function closeItem(data) {
    console.log(data)
    setForm({
      ...form,
      ...data
    });
    setIsSelected(false);
  }

  return (
    <View className='apply' style={`margin-top: ${navigationBarHeight}`}>
      <NavigationBar text="代理商备注" type="angentremark"/>
      <View className="box">
        <View className="from-item">
          <View className="label">手机号</View>
          <View className="space"></View>
          <View className="tip">{form.typeIndex ? form.mobile : '手机号'}</View>
        </View>
        <View className="from-item">
          <View className="label">用户真实姓名</View>
          <View className="space"></View>
          <View className="tip">{form.real_name ? form.real_name : '用户真实姓名'}</View>
        </View>
        <View className="from-item">
          <View className="label">所在地区</View>
          <View className="space"></View>
          <View className="tip">
            {
              form.launch_province_name ? `${form.launch_province_name}${form.launch_city_name || ''}${form.launch_region_name || ''}` : '所在地区'
            }
          </View>
        </View>
        <View className="from-item">
          <View className="label">投放地区</View>
          <View className="space"></View>
          <View className="tip">
            {
              form.province_name ? `${form.province_name}${form.city_name || ''}${form.region_name || ''}` : '投放地区'
            }
          </View>
        </View>

        <View className="from-item">
          <View className="label">选择类型</View>
          <View className="space"></View>
          <View className="tip">{form.type ? form.type : '类型'}</View>
          {/* <View className="tip">请选择卡劵类型</View> */}
        </View>
        {/* <View className="from-item">
          <View className="label">选择条状</View>
          <View className="space"></View>
          <View className="tip">请选择鱼的条状</View>
          <Image src={Next} className='next' />
        </View> */}
      </View>
      {type == false ? (
        <View className="apply-btn" onClick={handleSubmit}>填写资料</View>
      ) : (
          <View className="apply-btn" onClick={handleedit}>修改资料</View>
        )}
    </View>
  )
}

Apply.config = {
  navigationBarTitleText: '申领卡',
}

export default Apply;
